﻿using Coldairarrow.Business.MEGA;
using Coldairarrow.Entity.MEGA;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.MEGA
{
    [Route("/MEGA/[controller]/[action]")]
    public class MEGA_MaterialCategoryController : BaseApiController
    {
        #region DI

        public MEGA_MaterialCategoryController(IMEGA_MaterialCategoryBusiness mEGA_MaterialCategoryBus)
        {
            _mEGA_MaterialCategoryBus = mEGA_MaterialCategoryBus;
        }

        IMEGA_MaterialCategoryBusiness _mEGA_MaterialCategoryBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<MEGA_MaterialCategory>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_MaterialCategoryBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<MEGA_MaterialCategory> GetTheData(IdInputDTO input)
        {
            return await _mEGA_MaterialCategoryBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(MEGA_MaterialCategory data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _mEGA_MaterialCategoryBus.AddDataAsync(data);
            }
            else
            {
                await _mEGA_MaterialCategoryBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _mEGA_MaterialCategoryBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}